/*
 * SchulzeTest.java
 *
 * Copyright (C) 2014 Fabian Wenzelmann
 *
 * This file is part of stura_voting.
 *
 * stura_voting is free software: you
 * can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * stura_voting is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with stura_voting.
 *
 * If not, see <http://www.gnu.org/licenses/>.
 */

package de.stura.schulze;

import java.util.ArrayList;

// example from wikipedia <http://de.wikipedia.org/wiki/Schulze-Methode#Beispiel_1>
public class SchulzeTest {
    public static void main(String[] args) {
        SchulzeEvaluator eval = new SchulzeEvaluator(5);
        // first order 5 times
        // A: 0 B: 1 C: 2 D: 3 E: 4
        for (int i = 0; i < 5; ++i) {
            // A > C > B > E > D
            ArrayList<SchulzeVote> v = new ArrayList<SchulzeVote>();
            v.add(new SchulzeVote(0, 0));
            v.add(new SchulzeVote(2, 1));
            v.add(new SchulzeVote(1, 2));
            v.add(new SchulzeVote(4, 3));
            v.add(new SchulzeVote(3, 4));
            eval.addVote(v);
        }
        for (int i = 0; i < 5; ++i) {
            // A > D > E > C > B
            ArrayList<SchulzeVote> v = new ArrayList<SchulzeVote>();
            v.add(new SchulzeVote(0, 0));
            v.add(new SchulzeVote(3, 1));
            v.add(new SchulzeVote(4, 2));
            v.add(new SchulzeVote(2, 3));
            v.add(new SchulzeVote(1, 4));
            eval.addVote(v);
        }
        for (int i = 0; i < 8; ++i) {
            // B > E > D > A > C
            ArrayList<SchulzeVote> v = new ArrayList<SchulzeVote>();
            v.add(new SchulzeVote(1, 0));
            v.add(new SchulzeVote(4, 1));
            v.add(new SchulzeVote(3, 2));
            v.add(new SchulzeVote(0, 3));
            v.add(new SchulzeVote(2, 4));
            eval.addVote(v);
        }
        for (int i = 0; i < 3; ++i) {
            // C > A > B > E > D
            ArrayList<SchulzeVote> v = new ArrayList<SchulzeVote>();
            v.add(new SchulzeVote(2, 0));
            v.add(new SchulzeVote(0, 1));
            v.add(new SchulzeVote(1, 2));
            v.add(new SchulzeVote(4, 3));
            v.add(new SchulzeVote(3, 4));
            eval.addVote(v);
        }
        // A: 0 B: 1 C: 2 D: 3 E: 4
        for (int i = 0; i < 7; ++i) {
            // C > A > E > B > D
            ArrayList<SchulzeVote> v = new ArrayList<SchulzeVote>();
            v.add(new SchulzeVote(2, 0));
            v.add(new SchulzeVote(0, 1));
            v.add(new SchulzeVote(4, 2));
            v.add(new SchulzeVote(1, 3));
            v.add(new SchulzeVote(3, 4));
            eval.addVote(v);
        }
        for (int i = 0; i < 2; ++i) {
            // C > B > A > D > E
            ArrayList<SchulzeVote> v = new ArrayList<SchulzeVote>();
            v.add(new SchulzeVote(2, 0));
            v.add(new SchulzeVote(1, 1));
            v.add(new SchulzeVote(0, 2));
            v.add(new SchulzeVote(3, 3));
            v.add(new SchulzeVote(4, 4));
            eval.addVote(v);
        }
        for (int i = 0; i < 7; ++i) {
            // D > C > E > B > A
            ArrayList<SchulzeVote> v = new ArrayList<SchulzeVote>();
            v.add(new SchulzeVote(3, 0));
            v.add(new SchulzeVote(2, 1));
            v.add(new SchulzeVote(4, 2));
            v.add(new SchulzeVote(1, 3));
            v.add(new SchulzeVote(0, 4));
            eval.addVote(v);
        }
        for (int i = 0; i < 8; ++i) {
            // E > B > A > D > C
            ArrayList<SchulzeVote> v = new ArrayList<SchulzeVote>();
            v.add(new SchulzeVote(4, 0));
            v.add(new SchulzeVote(1, 1));
            v.add(new SchulzeVote(0, 2));
            v.add(new SchulzeVote(3, 3));
            v.add(new SchulzeVote(2, 4));
            eval.addVote(v);
        }
        ArrayList<ArrayList<Integer>> res = eval.evaluate();
        for (ArrayList<Integer> group : res) {
            System.out.print('[');
            boolean first = true;
            for (int val : group) {
                if (first) {
                    first = false;
                } else {
                    System.out.print(", ");
                }
                System.out.print(val);
            }
            System.out.println(']');
        }
    }
}
